/**
 * Copyright (C) 2013 phloc systems
 * http://www.phloc.com
 * office[at]phloc[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phloc.schematron.pure.bound.xpath;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import javax.xml.xpath.XPathExpression;

import com.phloc.commons.annotations.ReturnsMutableCopy;
import com.phloc.commons.collections.ContainerHelper;
import com.phloc.commons.string.StringHelper;
import com.phloc.schematron.pure.model.PSRule;

/**
 * This class represents a single XPath-bound rule-element.
 * 
 * @author philip
 */
@NotThreadSafe
final class PSXPathBoundRule
{
  private final PSRule m_aRule;
  private final String m_sRuleContext;
  private final XPathExpression m_aRuleContext;
  private final List <PSXPathBoundAssertReport> m_aAssertReports = new ArrayList <PSXPathBoundAssertReport> ();

  public PSXPathBoundRule (@Nonnull final PSRule aRule,
                           @Nonnull final String sRuleContext,
                           @Nonnull final XPathExpression aRuleContext)
  {
    if (aRule == null)
      throw new NullPointerException ("Rule");
    if (StringHelper.hasNoText (sRuleContext))
      throw new IllegalArgumentException ("RuleContext string");
    if (aRuleContext == null)
      throw new NullPointerException ("RuleContext");
    m_aRule = aRule;
    m_sRuleContext = sRuleContext;
    m_aRuleContext = aRuleContext;
  }

  @Nonnull
  public PSRule getRule ()
  {
    return m_aRule;
  }

  @Nonnull
  public String getRuleContextString ()
  {
    return m_sRuleContext;
  }

  @Nonnull
  public XPathExpression getRuleContextExpression ()
  {
    return m_aRuleContext;
  }

  public void addAssertReport (@Nonnull final PSXPathBoundAssertReport aXPathBoundAssertReport)
  {
    if (aXPathBoundAssertReport == null)
      throw new NullPointerException ("XPathBoundAssertReport");
    m_aAssertReports.add (aXPathBoundAssertReport);
  }

  @Nonnull
  @ReturnsMutableCopy
  public List <PSXPathBoundAssertReport> getAllAssertReports ()
  {
    return ContainerHelper.newList (m_aAssertReports);
  }
}
